로딩 중이에요... 🐣
[코담]
웹개발·실전 프로젝트·AI까지, 파이썬·장고의 모든것을 담아낸 강의와 개발 노트
2. pre commit설정 | ✅ 저자: 이유정(박사)
폴더명: ai_rest git링크: https://github.com/handgonpo/ai_rest/actions
mkdir AIRestaurant
cd AIRestaurant
python -m venv venv
source venv/bin/activate
pip install django
pip install black isort flake8 pre-commit # 개발도구
pip install pytest pytest-django coverage # 테스트도구
pip install django-environ ipython rich # 기타편의도구
pip install Pillow
pip freeze > requirements.txt
django-admin startproject proj .
python manage.py startapp restaurant
INSTALLED_APPS = [
...
'restaurant',
]
.pre-commit-config.yaml
설정 파일 생성
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
# - repo: https://github.com/pycqa/flake8
# rev: 7.0.0
# hooks:
# - id: flake8
# args: [--max-line-length=92]
pre-commit
초기화 및 Git에 연결
pip install pre-commit
pre-commit install
git init .
pre-commit install
git remote add origin https://github.com/handgonpo/ai_rest.git
git branch -M main
git reset
git pull origin main
git add .pre-commit-config.yaml
git commit -m "Add pre-commit config"
git push origin main
Actions 추가 : django-test.yml 을 작성한다.
name: Django CI
on:
push:
branches: [ "main","dev" ] # dev추가
pull_request:
branches: [ "main","dev" ] # dev추가
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.12.3] # 자신의 버전과 맞추기 python --version
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5 # 신버전으로 올리기
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
서버 실행
python manage.py runserver